﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Baby.Shop.HttpApi.Common
{
    /// <summary>
    /// 文件帮助类
    /// </summary>
    public class FileHelper
    {
        /// <summary>
        /// 
        /// </summary>
        public class FileInfos
        {
            /// <summary>
            /// 
            /// </summary>
            public string FileName { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string SkuIndex { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string FileExtension { get; set; }
        }
        /// <summary>
        /// 获取文件名称
        /// </summary>
        /// <returns></returns>
        public static FileInfos GetFileName(string path)
        {
            FileInfos infos =new FileInfos();
            string[] name = path.Trim().Split("+");
            Regex reg = new Regex(@"[\【\】]");  //去掉[]
            string fileNames = reg.Replace(name.Last(), " ");
            string[] fileName = fileNames.Split(".");
            infos.FileName = name.First()+Path.GetExtension(path);
            infos.SkuIndex = fileName.First().Trim();
            infos.FileExtension = Path.GetExtension(path);
            return infos;
        }
    }
}
